#include <iostream>
using namespace std;

const int &MAX = 200000;
const int &INFTY = 1 << 30;

int h, a[MAX + 1];

inline int parent(int i) {return i / 2;}
inline int left(int i) {return i * 2;}
inline int right(int i) {return 2 * i + 1;}

void maxHeapify(int i) {
    int l = left(i), r = right(i), lgest;
    if (l <= h && a[l] > a[i]) lgest = l;
    else lgest = i;
    if (r <= h && a[r] > a[lgest]) lgest = r;
    if (lgest != i) {
        std::swap(a[i], a[lgest]);
        maxHeapify(lgest);
    }
}

int extract() {
    int maxv;
    if (h < 1) return -INFTY;
    maxv = a[1];
    a[1] = a[h--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i, int key) {
    if (key < a[i]) return ;
    a[i] = key;
    while (i > 1 && a[i/2] < a[i]) {
        std::swap(a[i], a[i / 2]);
        i /= 2;
    }
}
void insert(int key) {
    ++h;
    a[h] = -INFTY;
    increaseKey(h, key);
}
int main() {
    insert(20);
    insert(30);
    insert(100);
    insert(45);

    cout << extract() << endl;
    return 0;
}